/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package SourceCode;

import java.io.Serializable;
import java.util.ArrayList;

/**
 *
 * @author ssaad
 */
public class Copy implements Serializable
{

    private  int copyid;
    private  boolean available;
    private Item item;
    public Loan loan ;
    public Copy(int copyid, Item item)
    {
        this.copyid = copyid;
        this.available = true;
        this.item = item;;
        item.addCopy(this);
        loan = null;
    }

    public void setAvailable(boolean available) {
        this.available = available;
    }

    public boolean IsAvailable()
    {
        return available;
    }

    public int getCopyid() {
        return copyid;
    }
    public Item getItem()
    {
        return this.item;
    }

    public void borrow(Loan loan)
    {
        this.loan = loan;
        if(loan.getCopy() != null)
            available = false;
        else
            available = true;
    }

    public void returncopy()
    {
        this.loan= null;
        available = true;
    }

    public String tostring()
    {
        if(IsAvailable())
            return "Copy ID: " + copyid + "  Available " + this.getItem().tostring();
        else
            return "Copy ID: "+ copyid + "  Not Available Type:" + this.getItem().tostring();

    }
    //check item reservation
    public boolean IsReserved()
    {
       if(this.getItem().reservations.size() > 0)
           return true;
       else
           return false;
    }

}
